package cn.zhanghu;
/**
 * Created by dell on 2017/7/3.
 */
public class GuiBing {
    private static void merge(int[] array,int i,int j,int middle){
        int[] temp=new int[array.length];
        int m=i;
        int k=i;
        int n=middle+1;
        while(m<=middle&&n<=j){
            if(array[m]>array[n])
                temp[k++]=array[n++];
            else
                temp[k++]=array[m++];
        }
        while(m<=middle){
            temp[k++]=array[m++];
        }
        while(n<=j){
            temp[k++]=array[n++];
        }
        while(i<=j){
            array[i]=temp[i++];
        }
    }
    private static void sort(int[] array,int i,int j){
        if(i<j){
            int middle=(i+j)/2;
            sort(array,i,middle);
            sort(array,middle+1,j);
            merge(array,i,j,middle);
        }
    }
    private static void Result(int[] result){
        for(int value:result){
            System.out.print(" "+value+" ");
        }
        System.out.println();
    }
    public static void main(String[] args) {
        int[] array = new int[]{1, 4, 5, 7, 2, 8, 3, 9, 10,6};
        sort(array, 0, array.length - 1);
        Result(array);

    }
}
